<?php
namespace Mobile\Controller;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){
        $data['status']=10;
        $dat=M('addver')->where($data)->select();

        foreach($dat as $key=>$value){
            $dat[$key]['picture']='/Public/upload/'.substr($dat[$key]['picture'],0,4).'/'.substr($dat[$key]['picture'],4,2).'/'.substr($dat[$key]['picture'],6,2).'/98_'.$dat[$key]['picture'];
        }

        $model=M();
        date_default_timezone_set('Asia/Shanghai');
        $time1=strtotime(date("Y-m-d",strtotime("+3 day")));
        $time2=strtotime(date('Y-m-d H:i:s',time()))+60*10;
        $sql="select m.name,m.cover,m.summary,m.actore,m.score,m.id from pre_screening s,pre_movie m where s.movie_id=m.id and m.status=10  and s.showtime>".$time2." and s.showtime<".$time1." order by s.showtime";
        $list=$model->query($sql);
       // var_dump($list);exit;
        foreach($list as $key=>$value){
            $list[$key]['cover']='/Public/upload/'.substr($list[$key]['cover'],0,4).'/'.substr($list[$key]['cover'],4,2).'/'.substr($list[$key]['cover'],6,2).'/96_'.$list[$key]['cover'];
            $comment=M('comment')->field('mark')->where(['movie_id'=>$value['id']])->select();
            $count=count($comment);
            foreach($comment as $val){
                $mark+=$val['mark'];
            }
            $smark=$mark/$count;
            if(is_int($smark)){
                $smark=$smark.'.0';
            }
            $list[$key]['comment']=$smark;
        }
        //dump($list);exit;
        $this->assign('dat',$dat);
        $this->assign('data',$list);
        $this->display();
    }


}